<template>
	<view class="container">
		<!--header-->
		<view class="search-header-box">
			<view class="search-header">
				<view class="search-searchbox">
					<view class="iconfont iconsousuohome" @tap="getProductList({size:20,num:1})"></view>
					<input class="search-input" v-model="searchKey" confirm-type="search" placeholder="请输入商品信息"
					@confirm="getProductList({size:20,num:1})"></input>
					<!-- <view class="search-clear iconfont iconguanbi1" v-if="searchKey"
					@tap="searchKeyFun"></view> -->
				</view>
			</view>
		</view>
		<view class="productList-wrap">
		<!-- 产品列表 -->
		<mescroll-body
			ref="mescrollRef" 
			@init="mescrollInit" 
			@down="downCallback"
			:up="upOption" 
			@up="getProductList"
			:fixed="true"
		>
			<view class="securityInfo">
				<view class="stockLess" v-for="(item,index) in safeStockList" :key='index' @tap="goDetail(item)">
					<view class="stockLeft">
						{{item.goodsName}}<span style='margin-left: 20rpx;'>{{item.goodsMatcode}}</span>
					</view>
					<view class="stockRight">
						<view class="stockRightNumber">
							<span class='fStockNum'>{{item.stockNum}}</span>个 
						</view>
						<view class="safeStockNumBox">
							<span class='iconfont iconanquan safeStockImg'></span>
							<span class='safeStockNum'>{{item.safeStockNum||0}}</span>
						</view>
						
					</view>
				</view>
				<view class="sum-number" v-if="safeStockList.length>0">
					总计：<span class='number'>{{totalcount}}个</span>
				</view>
			</view>
			
		</mescroll-body>
		</view>
		<loading></loading>
		<tui-modal></tui-modal>
	</view>
</template>

<script>
	import mixin from "@/utils/mixin.js"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins:[mixin,MescrollMixin],
		data() {
			return {
				searchKey: "", //搜索关键词
				safeStockList:[],
				upOption:{
					auto: false, // 不自动加载
					page: {
					 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					 	size: 20 // 每页数据的数量
					},
					noMoreSize: 20, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				},
				totalcount:0
			}
		},
		onShow() {
			// this.getProductList({size:20,num:1})
		},
		onLoad(options) {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
			if(options.searchText){
				this.searchKey=options.searchText
			}
		},
		mounted() {
			// 监听页面刷新
			this.$eventHub.$off('setStockPresent');
			this.$eventHub.$on('setStockPresent', () => {
			  this.mescroll.resetUpScroll();
			});
		},
		methods: {
			//商品列表
			getProductList(page) {
				let params={
					current:page.num,
					pageSize:page.size,
					searchText:this.searchKey
				};
				this.$http.tEsDealerGoodsStock(params).then((res) => {
					if (res.status === 0) {
						if(res.data.records.length>0){
							this.totalcount=res.data.records[0].totalcount
						}else{
							this.totalcount=0
						}
						let curPageData =res.data.records;
						this.mescroll.endSuccess(res.data.records.length);
						if (page.num == 1) {
							this.safeStockList = []
						};
						this.safeStockList = this.safeStockList.concat(curPageData);
						console.log(this.safeStockList)
					}
				}).catch(() => {
					this.mescroll.endErr()
				});
			},
			
			recordsIcon(){
				this.recordsList=[]
			},
			//搜索框输入
			searchKeyFun(){
				this.searchKey=''
			},
			goDetail(item){
				uni.navigateTo({
					url:'../goodsStockDetail/goodsStockDetail?type="0"&goodsId='+item.goodsId+'&goodsMatcode='+item.goodsMatcode+'&type=present'
				})
			},
		},
	}
</script>

<style lang="scss">
	.container {
		background: #fff;
		min-height: 100vh;
	}
	
	.historicRecords,.changeSearch{
		margin-top: 60rpx;
		padding: 60rpx 40rpx 80rpx 40rpx;
		background-color: #FFFFFF;
		color: #333333;
		// border-radius:0 0 50rpx 50rpx;
	}
	.changeSearch{
		padding: 20rpx 40rpx;
	}
	.recordsHeader{
		display: flex;
		justify-content: space-between;
	}
	.recordsContent{
		padding-top: 20rpx;
		display: flex;
		flex-wrap: wrap;
	}
	.records{
		font-size: 28rpx;
		border: 1px solid $borderColor;
		color: #333333;
		border-radius: 50rpx;
		margin: 10rpx 20rpx 10rpx 0;
		padding: 2rpx 20rpx;
		background-color: $borderColor;
	}
	.changeW{
		font-size: 28rpx;
		border-bottom: 1rpx solid $borderColor;
		padding: 20rpx 10rpx;
	}
	.parase-content {
		color: #333;
		font-size: 28rpx;
		// text-align: center;
		// display: flex;
	}
	.parase-content .em{
		color: #E94732 !important;
	}
	/* 隐藏scroll-view滚动条*/
	::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent;
	}
	.search-header-box {
		width: 100%;
		background: #fff;
		position: fixed;
		z-index: 99998;
		left: 0;
		top: 0;
		border-bottom: 2rpx solid $borderColor;
	}
	.search-header {
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}
	.search-searchbox {
		flex: 1;
		height: 70rpx;
		border-radius: 80rpx;
		font-size: 24rpx;
		// background: $borderColor;
		border:2rpx solid $themeColor1;
		padding: 6rpx 20rpx;
		box-sizing: border-box;
		color: #999;
		display: flex;
		align-items: center;
		overflow: hidden;
	}
	.search-input {
		text-align: left !important;
		margin-left: 12rpx;
		width: 100% !important;
		background-color: #fff !important;
		color:#121212;
		font-size: 28rpx;
		.uni-input-input {
			width: 100%;
			font-size: 30rpx;
		}
	}
	
	.search-text {
		font-size: 32rpx;
		color: #444;
		margin: 0 20rpx 0 30rpx;
		color: $red;
	}
	.search-search-text {
		padding-left: 16rpx;
	}
	.search-search-key {
		max-width: 80%;
		height: 100%;
		padding: 0 16rpx;
		margin-left: 12rpx;
		display: flex;
		align-items: center;
		border-radius: 15px;
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
	}
	.search-key-text {
		box-sizing: border-box;
		padding-right: 12rpx;
		font-size: 12px;
		line-height: 12px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.search-clear{
		padding:10rpx;
	}
	
	.securityInfo{
		padding: 0rpx 25rpx;
		margin-top: 100rpx;
		background-color: #fff;
		padding-bottom: 40rpx;
		.stockLess{
			padding: 15rpx 0;
			display: flex;
			justify-content:space-between;
			align-items: center;
			.stockLeft{
				width: 450rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 32rpx;
				color: #111111;
			}
			.stockRight{
				font-size: 28rpx;
				color: #111111;
				display: flex;
				align-items: center;
				.safeStockNumBox{
					background-color: #EA655E;
					color: #fff;
					border-radius: 20rpx;
					padding: 0 10rpx;
					display: flex;
					align-items: center;
					margin-left: 10rpx;
					max-width: 100rpx;
					
					.safeStockImg{
						font-size: 28rpx;
					}
					.safeStockNum{
						margin-left: 5rpx;
					}
				}
				
				.stockRightNumber{
					.fStockNum{
						color: #EA655E;
					}
				}
			}
		}
		.sum-number{
			width: 100%;
			padding: 20rpx 0;
			border-top: 2rp solid #f7f7f7;
			display:flex;
			 justify-content: flex-end;
			align-items: center;
			.number{
				margin-left: 10rpx;
				color: #EA655E;
			}
		}
	}
</style>
